package main

import (
	"fmt"
	"gitee.com/li-haowei/route"
	"net/http"
)

func getStudent(w http.ResponseWriter, r *http.Request) {
	params := r.URL.Query()
	grade := params.Get(":grade")
	name := params.Get(":name")
	fmt.Fprintf(w, "You get the Grade %s student's message, his name is %s.\n", grade, name)
}

func modifyStudent(w http.ResponseWriter, r *http.Request) {
	params := r.URL.Query()
	grade := params.Get(":grade")
	name := params.Get(":name")
	fmt.Fprintf(w, "You post the Grade %s student's message, his name is %s.\n", grade, name)
}

func addStudent(w http.ResponseWriter, r *http.Request) {
	params := r.URL.Query()
	grade := params.Get(":grade")
	name := params.Get(":name")
	fmt.Fprintf(w, "You put a new student message. The student named %s is in Grade %s\n", name, grade)
}

func deleteStudent(w http.ResponseWriter, r *http.Request) {
	params := r.URL.Query()
	grade := params.Get(":grade")
	name := params.Get(":name")
	fmt.Fprintf(w, "You delete the Grade %s student's message, his name is %s.\n", grade, name)
}

func main() {
	mux := route.New()
	mux.Get("/:grade/:name", getStudent)
	mux.Post("/:grade/:name", modifyStudent)
	mux.Put("/:grade/:name", addStudent)
	mux.Del("/:grade/:name", deleteStudent)

	http.Handle("/", mux)
	http.ListenAndServe(":8088", nil)
}